package LeetCode._03_链表;

public class _08奇偶链表 {
    public class ListNode {
        int val;
        ListNode next;
        ListNode() {}
        ListNode(int val) { this.val = val; }
        ListNode(int val, ListNode next) { this.val = val; this.next = next; }
    }

    public ListNode oddEvenList(ListNode head) {
        if(head == null || head.next == null) return head;
        ListNode t1 = head; //奇链表
        ListNode t2 = head.next; //偶链表
        ListNode t2Head = t2; //偶链表头

        while(t2!=null && t2.next!=null){ //t2.next!=null 满足节点个数为偶数的情况
            t1.next = t2.next;
            t1 = t1.next;
            t2.next = t1.next;
            t2 = t2.next;
        }
        t1.next = t2Head;
        return head;
    }
}
